Skip to content

Vectorized kernels in Parcels#2122

Merged
erikvansebille merged 64 commits intov4-devfrom
vectorized-kernel
Aug 19, 2025
Merged

Vectorized kernels in Parcels#2122
erikvansebille merged 64 commits intov4-devfrom
vectorized-kernel

Conversation

@erikvansebille
Copy link
Copy Markdown
Member

@erikvansebille erikvansebille commented Jul 29, 2025

One way to improve performance in Parcels is to 'vectorize' the kernels: i.e. to not make kernels loop over particles, but to have them act on the entire particles. This PR is an implementation of that approach.

The kernel loop has been completely rewritten, and for Parcels users there will be a few important changes

  1. Since the input of a kernel is a list of Particles (technically now a boolean mask of KernelParticles; but that may change in the refactor of Refactor particleset attributes and particle data for vectorized kernels #2143), users can't use if-statements anymore in their Kernels. Instead, they will need to apply np.where() or masked indexing. But note that even complex Kernels like RK45 with adaptive times-tapping are still possible
  2. The signature of a Kernel may need to change, because a) the input is not one particle but a set of particles and b) time does not have much meaning anymore when all particles could potentially have their own time. See also Reconsider Kernel signature for Parcels v4 #2147
  3. Users and developers may need to be a bit more careful of memory constraints. Since many variables in the Kernel loop are now arrays of length Nparticles, the memory requirements of temporary variables is now much more likely to grow quickly.
  4. The return value of a Kernel does not mean anything anymore, as particles can have different return states. Errors are therefore handled by their state
  5. Particle-particle interaction would potentially be much easier to be implemented, since all particles are available in the kernel (to be explored)

The performance of this PR has been explored in Parcels-code/parcels-benchmarks#2 (comment)

  • Chose the correct base branch (main for v3 changes, v4-dev for v4 changes)

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants